/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package persistence;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author breinesg
 */
@Entity
@Table(name = "SHELF")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Shelf.findAll", query = "SELECT s FROM Shelf s"),
    @NamedQuery(name = "Shelf.findShelf", query = "SELECT s FROM Shelf s WHERE s.libraryId = :library AND s.position= :position AND s.col = :col AND s.row = :row"),
    @NamedQuery(name = "Shelf.findByShelfId", query = "SELECT s FROM Shelf s WHERE s.shelfId = :shelfId"),
    @NamedQuery(name = "Shelf.findByPosition", query = "SELECT s FROM Shelf s WHERE s.position = :position"),
    @NamedQuery(name = "Shelf.findByCol", query = "SELECT s FROM Shelf s WHERE s.col = :col"),
    @NamedQuery(name = "Shelf.findByRow", query = "SELECT s FROM Shelf s WHERE s.row = :row")})
public class Shelf implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "SHELF_ID")
    private Integer shelfId;
    @Basic(optional = false)
    @NotNull
    @Column(name = "POSITION")
    private int position;
    @Basic(optional = false)
    @NotNull
    @Column(name = "COL")
    private int col;
    @Basic(optional = false)
    @NotNull
    @Column(name = "ROW")
    private int row;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "shelfId")
    private List<Medium> mediumList;
    @JoinColumn(name = "LIBRARY_ID", referencedColumnName = "LIBRARY_ID")
    @ManyToOne(optional = false)
    private Library libraryId;

    public Shelf() {
    }

    public Shelf(Integer shelfId) {
        this.shelfId = shelfId;
    }

    public Shelf(Integer shelfId, int position, int col, int row) {
        this.shelfId = shelfId;
        this.position = position;
        this.col = col;
        this.row = row;
    }

    public Integer getShelfId() {
        return shelfId;
    }

    public void setShelfId(Integer shelfId) {
        this.shelfId = shelfId;
    }

    public int getPosition() {
        return position;
    }

    public void setPosition(int position) {
        this.position = position;
    }

    public int getCol() {
        return col;
    }

    public void setCol(int col) {
        this.col = col;
    }

    public int getRow() {
        return row;
    }

    public void setRow(int row) {
        this.row = row;
    }

    @XmlTransient
    public List<Medium> getMediumList() {
        return mediumList;
    }

    public void setMediumList(List<Medium> mediumList) {
        this.mediumList = mediumList;
    }

    public Library getLibraryId() {
        return libraryId;
    }

    public void setLibraryId(Library libraryId) {
        this.libraryId = libraryId;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (shelfId != null ? shelfId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Shelf)) {
            return false;
        }
        Shelf other = (Shelf) object;
        if ((this.shelfId == null && other.shelfId != null) || (this.shelfId != null && !this.shelfId.equals(other.shelfId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "persistence.Shelf[ shelfId=" + shelfId + " ]";
    }
    
}
